#include "class-engine.h"

void cEngine::getMouse(sMouse &mouse){

	if(event.type == SDL_MOUSEBUTTONDOWN){

		if(event.button.button == SDL_BUTTON_LEFT){		
			mouse.leftDown = true;
		}else{
			mouse.leftDown = false;
		}

		if(event.button.button == SDL_BUTTON_MIDDLE){		
			mouse.middleDown = true;
		}else{
			mouse.middleDown = false;
		}

		if(event.button.button == SDL_BUTTON_RIGHT){		
			mouse.rightDown = true;
		}else{
			mouse.rightDown = false;
		}

		if(event.button.button == SDL_BUTTON_WHEELUP){		
			mouse.wheelUp = true;
		}else{
			mouse.wheelUp = false;
		}

		if(event.button.button == SDL_BUTTON_WHEELDOWN){		
			mouse.wheelDown = true;
		}else{
			mouse.wheelDown = false;
		}
	}

	if(event.type == SDL_MOUSEBUTTONUP){

		if(event.button.button == SDL_BUTTON_LEFT){		
			mouse.leftUp = true;
		}else{
			mouse.leftUp = false;
		}

		if(event.button.button == SDL_BUTTON_MIDDLE){		
			mouse.middleUp = true;
		}else{
			mouse.middleUp = false;
		}

		if(event.button.button == SDL_BUTTON_RIGHT){		
			mouse.rightUp = true;
		}else{
			mouse.rightUp = false;
		}
	}

	if(event.type == SDL_MOUSEMOTION){

		if (event.motion.x > 0 && event.motion.x < engine->SCREEN_WIDTH){
			if (event.motion.y > 0 && event.motion.y < engine->SCREEN_HEIGHT){

				mouse.x = event.motion.x;
				mouse.y = event.motion.y;

				mouse.xRel = event.motion.xrel;
				mouse.yRel = event.motion.yrel;

				// Set the Right movement vector
				mouse.rightVector.velocity = (sqrt((((float)entities[0]->x-mouse.x)*((float)entities[0]->x-mouse.x))+((entities[0]->y-mouse.y)*(entities[0]->y-mouse.y))) / sqrt(((float)engine->SCREEN_HEIGHT*(float)engine->SCREEN_HEIGHT)+((float)engine->SCREEN_WIDTH*(float)engine->SCREEN_WIDTH)))*100;
				mouse.rightVector.angle	   = atan2((float)(entities[0]->y-mouse.y),(float)(entities[0]->x-mouse.x));

				if (mouse.rightVector.velocity > 100){
					mouse.rightVector.velocity = 100;
				}
			}
		}

	}else{
		mouse.xRel = 0;
		mouse.yRel = 0;
	}
}